// components/home/index.js
const app = getApp();
let that;
Component({
  options: {
    addGlobalClass: true
  },

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    pageCur: '',
    lunbotuArr:[
      {
        id: 1,
        imageurl: "https://qiniu.camino.top/lunbotu1.jpg"
      },
      {
        id: 2,
        imageurl: "https://qiniu.camino.top/lunbotu2.jpg"
      },
      {
        id: 3,
        imageurl: "https://qiniu.camino.top/lunbotu3.jpg"
      },
      {
        id: 4,
        imageurl: "https://qiniu.camino.top/lunbotu4.jpg"
      },
       {
        id: 5,
        imageurl: "https://qiniu.camino.top/lunbotu5.jpg"
      }
    ],
    recommendList:[
      {
        avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
        videoUrl: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE%E7%A8%8B%E7%AC%AC%E4%B8%80%E8%AF%BE.mp4 ",
        id: 1,
        recommend_id: 1,
        subtitle: "بىرىنجى سائەتلىك دەرسلىكى",
        title: "جىيەنيىڭ دەرسلىكى ",
        price:"0.00",
        originalPrice:"88.00"
      },
      {
        avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
        videoUrl: "https://qiniu.camino.top/%E5%89%AA%E6%98%A0%E7%AC%AC%E4%BA%8C%E8%AF%BE.mp4",
        id: 2,
        recommend_id: 2,
        subtitle: "ئىككىنجى سائەتلىك دەرسلىكى",
        title: "جىيەنيىڭ دەرسلىكى ",
        price:"0.00",
        originalPrice:"99.00"
      },
      {
        avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
        videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E8%AF%BE%E7%A8%8B%E7%AC%AC%E4%B8%89%E8%AF%BE.mp4",
        id: 3,
        recommend_id: 3,
        subtitle: "ئۈچىنجى سائەتلىك دەرسلىكى",
        title: "جىيەنيىڭ دەرسلىكى ",
        price:"0.00",
        originalPrice:"121.00"
      },
      {
        avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
        videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E7%AC%AC%E5%9B%9B%E8%AF%BE.mp4",
        id: 4,
        recommend_id: 4,
        subtitle: "تۆتىنجى سائەتلىك دەرسلىكى",
        title: "جىيەنيىڭ دەرسلىكى ",
        price:"0.00",
        originalPrice:"55.00"
      },
       {
        avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
        videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E7%AC%AC%E4%BA%94%E8%AF%BE.mp4",
        id: 5,
        recommend_id: 5,
        subtitle: "بەشىنجى سائەتلىك دەرسلىكى",
        title: "جىيەنيىڭ دەرسلىكى ",
        price:"0.00",
        originalPrice:"121.00"
      },
      {
        avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
        videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E7%AC%AC%E5%85%AD%E8%AF%BE.mp4",
        id: 6,
        recommend_id: 6,
        subtitle: "ئالتىنجى سائەتلىك دەرسلىكى",
        title: "جىيەنيىڭ دەرسلىكى ",
        price:"0.00",
        originalPrice:"121.00"
      },
      {
        avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
        videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E7%AC%AC%E4%B8%83%E8%AF%BE.mp4",
        id: 7,
        recommend_id: 7,
        subtitle: "يەتتىنجى سائەتلىك دەرسلىكى",
        title: "جىيەنيىڭ دەرسلىكى ",
        price:"0.00",
        originalPrice:"78.00"
      },
    ]
  },

  /**
   * 组件的方法列表
   */
  attached() {
    that = this;
  },

  methods: {
    componentInnerFunction(e) {
      // this.requestApi()
      that.setData({
        pageCur: e,
      })
    
    },
    requestApi()
    {
      const that = this;
      wx.request({
        url: 'http://127.0.0.1:8000/lunbotu/',
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log('innerdata===',res.data)
          that.setData({
            lunbotuArr :res.data
          });
        },  
        fail: (err) => {
          console.error('请求失败:', err);
        }
      })

    },
    onClickItem(event) {
      // 从 event.currentTarget.dataset 获取 data-id 和 data-item
      const { id, item } = event.currentTarget.dataset;
      console.log('点击的ID:', id);      // 输出 data-id 的值
      console.log('点击的Item:', item);  // 输出 data-item 的值
      wx.navigateTo({
        url: '/pages/courseDetail/courseDetail?item=' + encodeURIComponent(JSON.stringify(item)) ,// 假设路径为 /pages/student/studentDetail/
        fail(err) {
          console.error('跳转失败:', err);
        }
      });
    },

    clickGrid(event){
      
    // 通过 event.currentTarget 获取被点击的 van-grid-item 元素
    const gridItem = event.currentTarget;
    
    // 获取自定义数据（如果有）
    const dataset = gridItem.dataset; 

    console.log('被点击的元素:', gridItem);
    console.log('元素上的自定义数据:', dataset);
    // 示例输出
    if(dataset.type == "honor")
    {
      wx.navigateTo({
        url: '/pages/companyHonor/companyHonor',
      })
    }else
    {
      wx.navigateTo({
        url: '/pages/aboutCompany/aboutCompany',
      })
    }
  },
    handleClick() {
      this.triggerEvent('tapAction')
    },
    handleContact(e) {
      console.log(e.detail.path)
      console.log(e.detail.query)
    }
  },
  
})